package game.module.message.processor;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import game.HallServer;
import game.entity.PlayingRole;
import game.session.SessionManager;
import lua.LuaMessageHall.PushScrollingMessage;

/**
 * 滚动消息推送
 * @ClassName: ScrollingMessageManager
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @author admin
 * @date 2017年8月28日
 *
 */
public class ScrollingMessageManager {

	private static Logger logger = LoggerFactory.getLogger(ScrollingMessageManager.class);


	static class SingletonHolder {
		static ScrollingMessageManager instance = new ScrollingMessageManager();
	}

	public static ScrollingMessageManager getInstance() {
		return SingletonHolder.instance;
	}


	/**
	 * 推送滚动消息
	 * @Title: PushScrollingMessage
	 * @Description: TODO(这里用一句话描述这个方法的作用)
	 * @param @param scrollid
	 * @param @param keyword    参数
	 * @return void    返回类型
	 * @throws
	 */
	public void pushScrollingMessage(int scrollid, String keyword) {
		//keyword 根据模板顺序替换关键词，使用“|”分隔；
		logger.info("滚动消息推送 PushScrollingMessage , scrollid={},keyword = {}", scrollid,keyword);
		HallServer.executorService.execute(new Runnable() {
			@Override
			public void run() {
				PushScrollingMessage pushMsg = new PushScrollingMessage(keyword, scrollid);
				for (PlayingRole pr : SessionManager.getInstance().getAllPlayers()) {
					pr.getGamePlayer().writeAndFlush(pushMsg.build(pr.alloc()));
				}
			}
		});
	}

}
